package com.example.demo.service.imp;

import com.example.demo.Expection.ApplicationException;
import com.example.demo.dao.UserMapper;
import com.example.demo.model.User;
import com.example.demo.service.ImpUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;

import javax.swing.plaf.synth.SynthOptionPaneUI;

@Controller
public class UserService implements ImpUserService {

    @Autowired
    UserMapper userMapper;
    @Override
    public User selectUserByName(String name) throws ApplicationException {
        if(name==null||!StringUtils.hasLength(name)){
            throw new ApplicationException("参数校验错误");
        }

        User user = userMapper.selectByUsername(name);


        return user;
    }

    @Override
    public void insertUser(User user) throws ApplicationException {
        System.out.println("2222222");
        if(user==null){
            throw new ApplicationException("参数校验失败");
        }
        System.out.println("DAAXAXAXAXAXAXA");
       Integer flag = userMapper.insertSelective(user);
        if(flag!=1){
            throw new ApplicationException("插入操作失败");
        }

    }
}
